package com.yuzhi.common.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * @EnumName: RainLevelEnum
 * @Author: Mario
 * @Description: 雨量等级枚举
 */
@Getter
@AllArgsConstructor
public enum RainLevelEnum {
    NO("无降雨", Double.MIN_EXPONENT, 0),
    TRACE("微量降雨（零星小雨）", 0, 0.1),
    LIGHT("小雨", 0.1, 4.9),
    MODERATE("中雨", 4.9, 14.9),
    HEAVY("大雨", 14.9, 29.9),
    STORM("暴雨", 29.9, 69.9),
    SEVERE_STORM("大暴雨", 69.9, 139.9),
    EXTREME_STORM("特大暴雨", 139.9, Double.MAX_VALUE);

    private final String desc;

    private final double min;

    private final double max;

    public static RainLevelEnum classifyRainfall(double rainValue) {
        return Arrays.stream(RainLevelEnum.values())
                .filter(level -> level.isInRange(rainValue))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("Invalid rainfall value"));
    }

    private boolean isInRange(double value) {
        return value > min && value <= max;
    }
}
